/**
 * @description excel导入导出
 * 注：/excel为固定路径，/exceldemo测试路径
 */
define([
  './libs/md5/spark-md5.min.js',
  './custom/widgets/js/yufpExcelExport.js',
  './custom/widgets/js/yufpExcelImport.js'
], function (require, exports) {
  exports.ready = function (hashCode, data, cite) {
    yufp.custom.vue({
      el: cite.el,
      data: function () {
        return {
          dialogVisible: false,
          showClose: true,
          title: '上传文件',
          height: '80px',
          width: '400px',
          model: 'import',
          percentage: 0,
          excelDemoGrid: {
            height: yufp.custom.viewSize().height - 162,
            currentRow: null,
            checkbox: false,
            dataUrl: backend.example + '/api/excel/queryList',
            dataParams: {},
            tableColumns: [
              { label: 'ID', prop: 'bookId', width: 150, resizable: true },
              { label: '标题', prop: 'title', width: 140, resizable: true },
              { label: '作者（字典项）', prop: 'author', resizable: true },
              { label: '日期（格式化yyyy-MM-dd）', prop: 'publishTime', resizable: true },
              { label: '售价（保留两位小数）', prop: 'price', resizable: true }
            ]
          },
          dialogFormVisible: false,
          // 导入
          importAction: backend.example + '/api/excel/import',
          // 导出
          startUrl: backend.example + '/api/excel/export',
          // 异步时导出、导入结果查询
          progressUrl: backend.example + '/api/excel/queryInfo',
          // 下载
          downloadUrl: backend.example + '/api/excel/download'
        };
      },
      computed: {
        action: function () {
          return yufp.service.getUrl({ url: this.uploadAction });
        }
      },
      methods: {
        importSuccess: function () { //导入成功后触发，刷新表格
        	this.$refs.excelDemo.remoteData();
        },
        exportTemplateFn: function () { // 导出模板操作
        	var url = yufp.settings.ssl ? 'https://' : 'http://';
            url += yufp.settings.url;
            url += backend.example;
            url += '/api/excel/exportTemplate';
            window.open(yufp.util.addTokenInfo(url));
        },
        successFn: function (taskId) { // 导出成功后触发
        	this.$message('成功下载任务《' + taskId + '》');
        }
      }
    });
  };
});